package main

import (
	"fmt"
	"crypto/elliptic"
	"math/big"
)

func hexprint(in []byte) {
	var i int
	for i = 0; i < len(in); i++ {
		fmt.Printf("%02X", in[i])
		/*		if i%4==3{
					fmt.Printf(" ")
				}*/
	}
	fmt.Println()
}

func CalPointDouble(){
	c:=elliptic.P256()
	x1,_:=new(big.Int).SetString("6B17D1F2E12C4247F8BCE6E563A440F277037D812DEB33A0F4A13945D898C296",16)
	y1,_:=new(big.Int).SetString("4FE342E2FE1A7F9B8EE7EB4A7C0F9E162BCE33576B315ECECBB6406837BF51F5",16)
	x2:=x1
	y2:=y1
	x3,y3:=c.Add(x1,y1,x2,y2)
	hexprint(x3.Bytes())
	hexprint(y3.Bytes())
}

func CalGmPointMul(){
	c:=elliptic.P256()
	x1,_:=new(big.Int).SetString("32C4AE2C1F1981195F9904466A39C9948FE30BBFF2660BE1715A4589334C74C7",16)
	y1,_:=new(big.Int).SetString("BC3736A2F4F6779C59BDCEE36B692153D0A9877CC62A474002DF32E52139F0A0",16)
	//x2:=x1
	//y2:=y1
	hexprint(c.Params().P.Bytes())
	k1,_:=new(big.Int).SetString("BC3736A2F4F6779C59BDCEE36B692153D0A9877CC62A474002DF32E52139F0A0",16)

	x3,y3:=c.ScalarBaseMult(k1.Bytes())
	hexprint(x3.Bytes())
	hexprint(y3.Bytes())
	k2,_:=new(big.Int).SetString("3",16)
	x4,y4:=c.ScalarMult(x1,y1,k2.Bytes())
	fmt.Println("double point:")
	hexprint(x4.Bytes())
	hexprint(y4.Bytes())


}

func main(){
	CalPointDouble()
//	CalGmPointMul()
//	elliptic.TestP256_Point()
//	elliptic.Test_amd64()
//	elliptic.Test_p256InternalFunc()
//	elliptic.Test_p256Func()
//	elliptic.TestP256_Point()
//	c:=elliptic.P256()
//	hexprint(c.Params().P.Bytes())
//	pri,_:=ecdsa.GenerateKey(c,rand.Reader)
//	hexprint(pri.D.Bytes())
//	hexprint(pri.X.Bytes())

}
